package mysql

import (
	"fmt"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"log"
	"tiktok/appconfig"
)

var DB *gorm.DB

func Init() {
	var err error
	var MysqlCon = appconfig.AppCon.Mysql
	dsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=True&loc=Local",
		MysqlCon.User, MysqlCon.Password, MysqlCon.Host, MysqlCon.Port, MysqlCon.Database)
	DB, err = gorm.Open(mysql.Open(dsn), &gorm.Config{})
	if err != nil {
		panic(err)
	}
	log.Println("数据库链接成功")

	DB.AutoMigrate(&TikTokContent{}, &TikTokUser{}, &TikTokComment{})
}
